<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>欢迎</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    <style>

    </style>
</head>
<body>
<h1>LOG IN</h1>
<div class="form-group" style="width: 30%">
<form id="myform" action="log_suc.jsp" method="post" role="form">

        <div class="alert alert-warning alert-dismissible" id="nameBox" role="alert" style="display: none"><b>Warning!</b> 用户名不得少于3位!</div>
    用户名：<label for="username"></label><input type="text" id="username" name="username">
    <div class="alert alert-warning alert-dismissible" id="pwdBox" role="alert" style="display: none"><b>Warning!</b> 密码不得少于5位!</div>
    密码：<label for="pwd"></label><input class="form-controal" type="password" id="pwd" name="pwd" ><br>
    验证码：<label for="checkcode"></label><input class="form-controal" type="text" id="checkcode" name="checkcode">
    <img class="img im" id="codeImg" src="${pageContext.request.contextPath}/action/CheckCode" onclick="refreshCode()"><br>
    <input type="hidden" name="actionName" value="Log_check">
    <input class="btn btn-default" type="button" onclick="check()" value="提交">
    <input class="btn btn-default" type="button" onclick="location='join.jsp'" value="注册">

</form>
</div>


<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.1.1.js"></script>
<script>
    $("#username").click(function () {
        $("#nameBox").hide();
    });
    $("#pwd").click(function () {
        $("#pwdBox").hide();
    });
    function check() {
        var username = $("#username").val();
        var password = $("#pwd").val();
        if (username !== null && username.length > 2) {
            if (password !== null && password.length > 4) {
                $.ajax({
                    url: "/JServlet",
                    type: "POST",
                    dataType:"text",
                    contentType: "application/x-www-form-urlencoded; charset=utf-8",
                    data: $("#myform").serialize(),
                    success:function (data,status) {
                        alert(data+"数据发送状态："+status);
                        if(data.search("log_suc")!==-1){
                            console.log("跳转");
                            document.getElementById('myform').submit();
                        }else {
                            alert("数据发送状态："+status+"\n"+data);
                        }
                    }
                });
            } else {
                $("#pwdBox").show();
            }
        } else {
            $("#nameBox").show();
        }
    }
</script>
</body>
</html>
